#include "stdafx.h"

#include <MyFC/GlyphButton.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

namespace My {

GlyphButton::GlyphButton(LPCTSTR szGlyph, LPCTSTR szMask)
{ 
	m_Glyph.Load(szGlyph, szMask);
	m_Grayed.Load(szGlyph, szMask);
}

void GlyphButton::SetGlyph(LPCTSTR szGlyph, LPCTSTR szMask)
{
	m_Glyph.Load(szGlyph, szMask);
	m_Grayed.Load(szGlyph, szMask);
	Invalidate();
}

CSize GlyphButton::GetPreferredSize() const
{
	return m_Glyph.Size();
}

void GlyphButton::HandlePaint(CDC * pDC, const CRect & r)
{
	CRect rClient = ClientRect();
	CBrush bFace; bFace.CreateSysColorBrush(COLOR_BTNFACE);	
	pDC->FillRect(&rClient, &bFace);

	COLORREF cLight = GetSysColor(COLOR_BTNHILIGHT);
	COLORREF cShadow = GetSysColor(COLOR_BTNSHADOW);

	if (!ControlEnabled(this) || (GetState() != Down))
		pDC->Draw3dRect(&rClient, cLight, cShadow);
	else
		pDC->Draw3dRect(&rClient, cShadow, cLight);

	if (!ControlEnabled(this))
		m_Grayed.Draw(pDC, rClient);
	else {
		if (GetState() == Down)
			rClient.OffsetRect(1, 1);
		m_Glyph.Draw(pDC, rClient);
	}
}

} // My